import sys
sys.path.insert(0,'../../../')

import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ihome.settings.dev')

import django
django.setup()

from django.http import JsonResponse
from django.conf import settings
from wangziye.models import House, Order
from datetime import datetime

def Aoo(house_id):
    house = House.objects.get(id=house_id)
    list1 = []
    comments = Order.objects.filter(house=house_id)
    for comment in comments:
        list1.append({
            'comment': comment.comment,
            'ctime': comment.create_time.strftime('%Y-%m-%d %H:%M:%S'),
            'user_name': comment.user.username
        })
    list2 = []
    b = house.facility.all()
    for c in b:
        list2.append(c.id)
    list3 = []
    list3.append(house.index_image_url)

    a = ({
        'data': {"house": {
            "acreage": house.acreage,
            "address": house.address,
            "beds": house.beds,
            "capacity":house.capacity,
            "comments":list1,
            "deposit":house.deposit,
            "facilities":list2,
            "hid":house_id,
            "img_urls":list3,
            "max_days":house.max_days,
            "min_days":house.min_days,
            "price":house.price,
            "room_count":house.room_count,
            "title":house.title,
            "unit":house.unit,
            # "user_avatar":request.user.avatar,
            # "user_id":request.user.id,
            # "user_name":request.user.username
        },
            'user_id': 1},
        'errmsg': 'ok',
        'errno': '0'
    })
    return a

if __name__ == '__main__':
    a = Aoo(5)
    print(a)